﻿using DeZhen.Core.Framework.Business.Ioc;
using DeZhen.Core.Framework.Entity;
using DeZhen.Core.Redis.Service;
using DeZhen.Core.SqlSugar.Repository;
using DeZhen.Core.Template.Domain.Entity.TableEntity;
using DeZhen.Core.Template.Domain.IRepository;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace DeZhen.Core.Template.Repository.Repository
{
    [Service(ServiceLifetime.Transient)]
    public class UserRepository:BaseRepository, IUserRepository
    {
        [Autowired]
        private IRedisPlatform _redisPlatform;
        public UserRepository(IAutowiredPlatform autowiredService) : base("1")
        {
            autowiredService.Autowired(this);
        }
        public async Task<List<UserInfo>> GetUserInfoFromDataBaseAsync()
        {
            return await SqlClient.Queryable<UserInfo>().ToListAsync();
        }
        public async Task<int> CreateUserInfoToDataBase(UserInfo entity)
        {
            return await SqlClient.Insertable<UserInfo>(entity).ExecuteCommandAsync();
        }
        public async Task<UserInfo> GetUserInfoFromRedisAsync(String key)
        {
            return await _redisPlatform.GetAsync<UserInfo>(key);
        }
        public async Task<bool> CreateUserInfoToRedis(String key,UserInfo entity)
        {
            return await _redisPlatform.SetAsync(key, entity);
        }

    }
}
